#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
	const int MAX = 4;
	int digitsA[MAX], digitsB[MAX];
	int T;
	cin>>T;

	int A, B;
	int base = 10;
	int both = 0, single = 0;
	for (int i = 0; i < T; i++) {
		cin>>A>>B;
		both = 0;
		single = 0;
		for (int i = 0; i < MAX; i++) {
			digitsA[i] = A % 10;
			A = (A - digitsA[i]) / 10;

			digitsB[i] = B % 10;
			B = (B - digitsB[i]) / 10;
		}

		for (int i = 0; i < MAX; i++) {
			for (int j = 0; j < MAX; j++) {
				if (digitsA[i] == digitsB[j]) {
					if (i == j)
						++both;
					else
						++single;
				}
			}
		}

		cout<<both<<"A"<<single<<"B"<<endl;

	}
	return 0;
}